#include "plane.h"

e3dPlane::e3dPlane (void) : normal   (0.0f, 0.0f, 0.0f),
                            dist     (0.0f),

                            type     (0),
                            signbits (0)
{
}

e3dPlane::~e3dPlane (void)
{
  // Nothing to do :)
}

#if 0
////////////////////////////////////////////////////////////////////////////////
// Global Methods
/////////////////

/* Does the given line intersect with the given plane? */
bool IntersectedPlane ( e3dVector3  vPoly [],
                        e3dVector3  vLine [],
                        e3dVector3 &vNormal,
                        float      &originDistance )
{
  float distance1 = 0.0f,
        distance2 = 0.0f;

  vNormal = vPoly.Norm ();//Normal (vPoly);

  originDistance = PlaneDistance (vNormal, vPoly [0]);

  // Get the distance to point1 from the plane using: Ax + By + Cz + D = (The distance from the plane)

  distance1 = ((vNormal.x * vLine [0].x)  +                  // Ax +
               (vNormal.y * vLine [0].y)  +                  // Bx +
               (vNormal.z * vLine [0].z)) + originDistance;  // Cz + D

  // Get the distance to point2 from the plane using Ax + By + Cz + D = (The distance from the plane)

  distance2 = ((vNormal.x * vLine [1].x)  +                  // Ax +
               (vNormal.y * vLine [1].y)  +                  // Bx +
               (vNormal.z * vLine [1].z)) + originDistance;  // Cz + D

  /* The logic behind this is simple, if both distances are positive or negative,
     multiplication will result in a positive floating point... Otherwise, it will
     be negative. If it's positive, the points lie on the same side of the plane */
  if (distance1 * distance2 >= 0)
     return false;

  return true;
}


/* Tells if a sphere is BEHIND, in FRONT, or INTERSECTS a plane,
   also tells the distance between the sphere and the plane. */
int ClassifySphere ( e3dVector3 &vCenter,
             e3dVector3 &vNormal,
                     e3dVector3 &vPoint,
                     float       radius,
                     float      &distance )
{
  // First we need to find the distance our polygon plane is from the origin.
  float d = (float)PlaneDistance (vNormal, vPoint);

  // Here we use the famous distance formula to find the distance the center point
  // of the sphere is from the polygon's plane.
  distance = (vNormal.x * vCenter.x + vNormal.y * vCenter.y + vNormal.z * vCenter.z + d);

  // If the absolute value of the distance we just found is less than the radius,
  // the sphere intersected the plane.
  if (Absolute (distance) < radius)
    return INTERSECTS;
  // Else, if the distance is greater than or equal to the radius, the sphere is
  // completely in FRONT of the plane.
  else if (distance >= radius)
    return FRONT;

  // If the sphere isn't intersecting or in FRONT of the plane, it must be BEHIND
  return BEHIND;
}
#endif
